package com.test;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by baiguantao on 2017/8/3.
 */
public class Java8Learn {
    /**
     * 重复生成流
     */
    @Test
    public void testStreamIterate(){
        Stream.iterate(new int[]{0, 1},t -> new int[]{t[1], t[0]+t[1]})
                .limit(20)
                .forEach(t -> System.out.println("(" + t[0] + "," + t[1] +")"));
    }
    @Test
    public  void testStreamGenerate() {
        Stream.generate(Math::random).limit(5).forEach(System.out::println);
    }


    @Test
    public  void testStreamCollect() {
        List<String> stringslist= Arrays.asList("ricky","sherry","lucy");
        List<String> strings=stringslist.stream().filter(s->s.length()>=5).collect(Collectors.toList());
                //.map(s->s.toString())
                //.forEach(System.out::println);
        strings.stream().forEach(System.out::println);
    //    处理器数量
        System.out.println("处理器数量："+Runtime.getRuntime().availableProcessors());
    }


}
